package bean;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;

/**
 * Servlet implementation class Teste
 */
@WebServlet("/Teste")
public class Teste extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public Teste() {
        super();
        System.out.println("Teste");
    }

    @Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
		System.out.println("Teste1");
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("Teste2");
		String url = "http://187.1.85.38:98/scriptcase/app/CORPORATIVO/Blk_Ws_Control/Blk_Ws_Control.php";
		String tipoTransacao = "3";
		String login = "LWSMCPADRAO";
		String senha = "minascap@$2014";
		String datasorteio = "2014-07-21";
		String codEmpresa = "678";

		Client c = Client.create();
		WebResource wr = c.resource(url);

	    
	    MultivaluedMap<String, String> formData = new MultivaluedMapImpl();
	    formData.add("tipoTransacao", tipoTransacao);
	    formData.add("login", login);
	    formData.add("senha", senha);
	    formData.add("datasorteio", datasorteio);
	    formData.add("codEmpresa", codEmpresa);
	    ClientResponse res = wr.type("application/x-www-form-urlencoded").post(ClientResponse.class, formData);

		//System.out.println("Retorno:" + res.toString());
		System.out.println("Saida: " + res.getEntity(String.class));

		
	}

}
